{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Part of this file can't be rendered in GitHub. Refer to the following link for a properly rendered version of this file: https://nbviewer.jupyter.org/github/sfu-db/dataprep/blob/develop/examples/DataConnector_Yelp.ipynb"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Connector for Yelp \n",
    "\n",
    "In this example, we will be going over how to use Connector with Yelp."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Prerequisites\n",
    "\n",
    "Connector is a component in the DataPrep library that aims to simplify data access by providing a standard API set. The goal is to help users skip the complex API configuration. In this tutorial, we demonstrate how to use the connector component with Yelp.\n",
    "\n",
    "If you haven't installed DataPrep, run command `!pip install dataprep` or execute the following cell."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Run me if you'd like to install\n",
    "!pip install dataprep"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Download and store the configuration files in DataPrep. \n",
    "\n",
    "The configuration files are used to configure the parameters and initial setup for the API. The available configuration files can be manually downloaded here: [Configuration Files](https://github.com/sfu-db/DataConnectorConfigs) or automatically downloaded at usage. \n",
    "\n",
    "Store the configuration file in the dataprep folder. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Obtaining an access token from Yelp\n",
    "\n",
    "To connect to Yelp, you need to generate a token. This token is a unique identifier of an application requesting access to the Yelp's API. Once an application creates the token, it will act as your credential when making an API request. \n",
    "\n",
    "To receive an access token, the user needs to create a server-side application from Yelp. You can get a token by following the [Yelp document](https://www.yelp.com/developers/documentation/v3/authentication).\n",
    "Simply create an application and generate a key."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Store the token or API Key in a secure location as it will provide you access to Yelp's data."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Initialize connector\n",
    "\n",
    "Copy and paste your API key as the value for the **auth_token** variable. Ensure the **API name** argument is correct. This establishes a connection with Twitter and returns an object. Once you run the code you can use the built in functions available from connector."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from dataprep.connector import connect, info\n",
    "\n",
    "auth_token = '<insert API key>'\n",
    "dc = connect('yelp', _auth={'access_token':auth_token})\n",
    "\n",
    "dc"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Functionalities\n",
    "\n",
    "Connector has several functions you can perform to gain insight on the data downloaded from Yelp."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Connector.info\n",
    "The info method gives information and guidelines on using the connector. There are 4 sections in the response and they are table, parameters, example and schema.\n",
    "\n",
    ">1. Table - The table(s) being accessed.\n",
    ">2. Parameters - Identifies which parameters can be used to call the method.\n",
    ">3. Examples - Shows how you can call the methods in the Connector class.\n",
    ">4. Schema - Names and data types of attributes in the response."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<html>\n",
       "    <head>\n",
       "        <title> DataPrep.Connector Info </title>\n",
       "        <script>\n",
       "            function switchTab637(e) {\n",
       "                const selectedAreaSuffix = e.parentElement.parentElement.className.split('-')[1];\n",
       "                const selectedTabId = e.id.split('-')[2];\n",
       "                const selectedTabContent = document.querySelector(`.contents-${selectedAreaSuffix}>div:nth-of-type(${selectedTabId})`);\n",
       "                const contentArray = document.getElementsByClassName('info-637')\n",
       "                for (let i of contentArray) {\n",
       "                    i.style.display = 'none';\n",
       "                }\n",
       "                selectedTabContent.style.display = 'block';\n",
       "            }\n",
       "        </script>\n",
       "        <style>\n",
       "            .container-637 {\n",
       "            }\n",
       "            .container-637 input[type=radio] {\n",
       "            display: none;\n",
       "            }\n",
       "            .tabs-637 {\n",
       "            font-family: -apple-system, 'Helvetica Neue', 'Helvetica', 'Arial', 'Lucida Grande', sans-serif;\n",
       "            -webkit-font-smoothing: antialiased;\n",
       "            display: grid;\n",
       "            flex-wrap: wrap;\n",
       "            gap: 5px;\n",
       "            grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));\n",
       "            justify-content: wrap;\n",
       "            }\n",
       "            .tabs-637 label {\n",
       "            word-wrap: break-word;\n",
       "            text-align: center;\n",
       "            font-size: 12px;\n",
       "            border-bottom: 2px solid #9edae5;\n",
       "            transition: border 0.3s ease;\n",
       "            }\n",
       "            .tabs-637 label:hover {\n",
       "            background: rgba(0, 0, 0, 0.1);\n",
       "            }\n",
       "            .tabs-637 input:checked+label {\n",
       "            border-bottom: 2px solid #1f77b4;\n",
       "            }\n",
       "            .contents-637>div:nth-of-type(n+2) {\n",
       "            display: none;\n",
       "            }\n",
       "            h4 {\n",
       "            font-size: 14px;\n",
       "            font-family: Arial;\n",
       "            }\n",
       "            p {\n",
       "            font-size: 13px;\n",
       "            }\n",
       "        </style>\n",
       "    </head>\n",
       "    <body>\n",
       "        <div class=\"container-637\">\n",
       "            <div class=\"tabs-637\">\n",
       "                <input type=\"radio\" name=\"select\" id='tab-637-1' checked onclick=\"switchTab637(this)\">\n",
       "                <label for=\"tab-637-1\">businesses</label>\n",
       "                \n",
       "                \n",
       "                \n",
       "                    \t\t\n",
       "            </div>\n",
       "            <div class=\"contents-637\">\n",
       "                \n",
       "                <div class=\"info-637\">\n",
       "                    <div>\n",
       "                        <h4><u>Parameters</u></h4>\n",
       "                        \n",
       "                        \n",
       "                        <p style=\"display:wrap\"><code>location (required)</code></p>\n",
       "                        \n",
       "                        \n",
       "                        \n",
       "                        \n",
       "                        <p style=\"display:wrap\"><code>term</code></p>\n",
       "                        \n",
       "                        <p style=\"display:wrap\"><code>latitude</code></p>\n",
       "                        \n",
       "                        <p style=\"display:wrap\"><code>longitude</code></p>\n",
       "                        \n",
       "                        <p style=\"display:wrap\"><code>limit</code></p>\n",
       "                        \n",
       "                        \n",
       "                        \n",
       "                    </div>\n",
       "                    <div>\n",
       "                        <h4><u>Example</u></h4>\n",
       "                        \n",
       "                        \n",
       "                        \n",
       "                        \n",
       "                        \n",
       "                        \n",
       "                        \n",
       "                        \n",
       "                        \n",
       "                        \n",
       "                        \n",
       "                        \n",
       "                        <p><code>dc = connect('yelp', _auth={'access_token':'cCMHU4M4t7rdt*********vp3whGzFjgIKIm0'}, _concurrency=3)<br>df = await dc.query('businesses', location='seattle', _count=20)</code></p>\n",
       "                    </div>\n",
       "                    <div>\n",
       "                    \t<h4><u>Schema</u></h4>\n",
       "                    \t<style  type=\"text/css\" >\n",
       "    #T_9081d65c_35b1_11eb_bcde_c82a14415709 th {\n",
       "          background: white;\n",
       "          font-weight: bold;\n",
       "          text-align: right;\n",
       "          font-family: arial;\n",
       "          font-size: 13;\n",
       "    }    #T_9081d65c_35b1_11eb_bcde_c82a14415709 td {\n",
       "          font-family: arial;\n",
       "    }    #T_9081d65c_35b1_11eb_bcde_c82a14415709 tr:nth-of-type(odd) {\n",
       "          background: #f5f5f5;\n",
       "          font-size: 13;\n",
       "          text-align: right;\n",
       "    }    #T_9081d65c_35b1_11eb_bcde_c82a14415709 tr:nth-of-type(even) {\n",
       "          background: #white;\n",
       "          font-size: 13;\n",
       "          text-align: right;\n",
       "    }    #T_9081d65c_35b1_11eb_bcde_c82a14415709 tr:hover {\n",
       "          background-color: e0f1ff;\n",
       "    }</style><table id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709\" ><thead>    <tr>        <th class=\"blank level0\" ></th>        <th class=\"col_heading level0 col0\" >column_name</th>        <th class=\"col_heading level0 col1\" >data_type</th>    </tr></thead><tbody>\n",
       "                <tr>\n",
       "                        <th id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709level0_row0\" class=\"row_heading level0 row0\" >0</th>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row0_col0\" class=\"data row0 col0\" >id</td>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row0_col1\" class=\"data row0 col1\" >string</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709level0_row1\" class=\"row_heading level0 row1\" >1</th>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row1_col0\" class=\"data row1 col0\" >alias</td>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row1_col1\" class=\"data row1 col1\" >string</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709level0_row2\" class=\"row_heading level0 row2\" >2</th>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row2_col0\" class=\"data row2 col0\" >name</td>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row2_col1\" class=\"data row2 col1\" >string</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709level0_row3\" class=\"row_heading level0 row3\" >3</th>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row3_col0\" class=\"data row3 col0\" >image_url</td>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row3_col1\" class=\"data row3 col1\" >string</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709level0_row4\" class=\"row_heading level0 row4\" >4</th>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row4_col0\" class=\"data row4 col0\" >is_closed</td>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row4_col1\" class=\"data row4 col1\" >boolean</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709level0_row5\" class=\"row_heading level0 row5\" >5</th>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row5_col0\" class=\"data row5 col0\" >url</td>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row5_col1\" class=\"data row5 col1\" >string</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709level0_row6\" class=\"row_heading level0 row6\" >6</th>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row6_col0\" class=\"data row6 col0\" >review_count</td>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row6_col1\" class=\"data row6 col1\" >int</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709level0_row7\" class=\"row_heading level0 row7\" >7</th>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row7_col0\" class=\"data row7 col0\" >rating</td>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row7_col1\" class=\"data row7 col1\" >float</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709level0_row8\" class=\"row_heading level0 row8\" >8</th>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row8_col0\" class=\"data row8 col0\" >latitude</td>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row8_col1\" class=\"data row8 col1\" >float</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709level0_row9\" class=\"row_heading level0 row9\" >9</th>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row9_col0\" class=\"data row9 col0\" >longtitude</td>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row9_col1\" class=\"data row9 col1\" >float</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709level0_row10\" class=\"row_heading level0 row10\" >10</th>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row10_col0\" class=\"data row10 col0\" >categories</td>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row10_col1\" class=\"data row10 col1\" >object</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709level0_row11\" class=\"row_heading level0 row11\" >11</th>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row11_col0\" class=\"data row11 col0\" >address1</td>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row11_col1\" class=\"data row11 col1\" >string</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709level0_row12\" class=\"row_heading level0 row12\" >12</th>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row12_col0\" class=\"data row12 col0\" >address2</td>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row12_col1\" class=\"data row12 col1\" >string</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709level0_row13\" class=\"row_heading level0 row13\" >13</th>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row13_col0\" class=\"data row13 col0\" >address3</td>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row13_col1\" class=\"data row13 col1\" >string</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709level0_row14\" class=\"row_heading level0 row14\" >14</th>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row14_col0\" class=\"data row14 col0\" >city</td>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row14_col1\" class=\"data row14 col1\" >string</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709level0_row15\" class=\"row_heading level0 row15\" >15</th>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row15_col0\" class=\"data row15 col0\" >country</td>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row15_col1\" class=\"data row15 col1\" >string</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709level0_row16\" class=\"row_heading level0 row16\" >16</th>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row16_col0\" class=\"data row16 col0\" >state</td>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row16_col1\" class=\"data row16 col1\" >string</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709level0_row17\" class=\"row_heading level0 row17\" >17</th>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row17_col0\" class=\"data row17 col0\" >zip_code</td>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row17_col1\" class=\"data row17 col1\" >string</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709level0_row18\" class=\"row_heading level0 row18\" >18</th>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row18_col0\" class=\"data row18 col0\" >phone</td>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row18_col1\" class=\"data row18 col1\" >string</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709level0_row19\" class=\"row_heading level0 row19\" >19</th>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row19_col0\" class=\"data row19 col0\" >distance</td>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row19_col1\" class=\"data row19 col1\" >string</td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                        <th id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709level0_row20\" class=\"row_heading level0 row20\" >20</th>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row20_col0\" class=\"data row20 col0\" >price</td>\n",
       "                        <td id=\"T_9081d65c_35b1_11eb_bcde_c82a14415709row20_col1\" class=\"data row20 col1\" >string</td>\n",
       "            </tr>\n",
       "    </tbody></table>\n",
       "                    </div>\n",
       "                </div>\n",
       "                \n",
       "            </div>\n",
       "        </div>\n",
       "    </body>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "info('yelp')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Connector.query\n",
    "The query method downloads the website data and displays it in a Dataframe. The parameters must meet the requirements as indicated in connector.info for the operation to run.\n",
    "\n",
    "When the data is received from the server, it will either be in a JSON or XML format. The connector reformats the data in pandas Dataframe for the convenience of downstream operations.\n",
    "\n",
    "As an example, let's try to get data from the \"business\" table, providing the term \"city\" and location \"seattle\"."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>rating</th>\n",
       "      <th>price</th>\n",
       "      <th>phone</th>\n",
       "      <th>name</th>\n",
       "      <th>url</th>\n",
       "      <th>latitude</th>\n",
       "      <th>longtitude</th>\n",
       "      <th>city</th>\n",
       "      <th>country</th>\n",
       "      <th>address2</th>\n",
       "      <th>address3</th>\n",
       "      <th>state</th>\n",
       "      <th>address1</th>\n",
       "      <th>zip_code</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>3.5</td>\n",
       "      <td>None</td>\n",
       "      <td>+12066842489</td>\n",
       "      <td>City of Seattle</td>\n",
       "      <td>https://www.yelp.com/biz/city-of-seattle-seatt...</td>\n",
       "      <td>47.602820</td>\n",
       "      <td>-122.329260</td>\n",
       "      <td>Seattle</td>\n",
       "      <td>US</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>WA</td>\n",
       "      <td></td>\n",
       "      <td>98104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3.5</td>\n",
       "      <td>$</td>\n",
       "      <td>+12063231715</td>\n",
       "      <td>City Market</td>\n",
       "      <td>https://www.yelp.com/biz/city-market-seattle?a...</td>\n",
       "      <td>47.617043</td>\n",
       "      <td>-122.326439</td>\n",
       "      <td>Seattle</td>\n",
       "      <td>US</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>WA</td>\n",
       "      <td>1722 Bellevue Ave</td>\n",
       "      <td>98122</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4.0</td>\n",
       "      <td>$$</td>\n",
       "      <td>+12066829329</td>\n",
       "      <td>City Fish</td>\n",
       "      <td>https://www.yelp.com/biz/city-fish-seattle-2?a...</td>\n",
       "      <td>47.608754</td>\n",
       "      <td>-122.340636</td>\n",
       "      <td>Seattle</td>\n",
       "      <td>US</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>WA</td>\n",
       "      <td>1535 Pike Pl</td>\n",
       "      <td>98101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3.0</td>\n",
       "      <td>$$$</td>\n",
       "      <td>+12064413663</td>\n",
       "      <td>City Foods</td>\n",
       "      <td>https://www.yelp.com/biz/city-foods-seattle?ad...</td>\n",
       "      <td>47.617890</td>\n",
       "      <td>-122.345820</td>\n",
       "      <td>Seattle</td>\n",
       "      <td>US</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>WA</td>\n",
       "      <td>2522 5th Ave</td>\n",
       "      <td>98121</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5.0</td>\n",
       "      <td>None</td>\n",
       "      <td>+12066824424</td>\n",
       "      <td>City Chiropractic</td>\n",
       "      <td>https://www.yelp.com/biz/city-chiropractic-sea...</td>\n",
       "      <td>47.612790</td>\n",
       "      <td>-122.336560</td>\n",
       "      <td>Seattle</td>\n",
       "      <td>US</td>\n",
       "      <td>Ste 1645</td>\n",
       "      <td></td>\n",
       "      <td>WA</td>\n",
       "      <td>509 Olive Way</td>\n",
       "      <td>98101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>4.5</td>\n",
       "      <td>$$</td>\n",
       "      <td>+12063240737</td>\n",
       "      <td>City People's Garden Store</td>\n",
       "      <td>https://www.yelp.com/biz/city-peoples-garden-s...</td>\n",
       "      <td>47.624580</td>\n",
       "      <td>-122.294240</td>\n",
       "      <td>Seattle</td>\n",
       "      <td>US</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>WA</td>\n",
       "      <td>2939 E Madison St</td>\n",
       "      <td>98112</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>3.0</td>\n",
       "      <td>$$</td>\n",
       "      <td>+12064943250</td>\n",
       "      <td>Target</td>\n",
       "      <td>https://www.yelp.com/biz/target-seattle-7?adju...</td>\n",
       "      <td>47.608941</td>\n",
       "      <td>-122.339058</td>\n",
       "      <td>Seattle</td>\n",
       "      <td>US</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>WA</td>\n",
       "      <td>1401 2nd Ave</td>\n",
       "      <td>98101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>3.0</td>\n",
       "      <td>None</td>\n",
       "      <td>+14257756477</td>\n",
       "      <td>City of Mountlake Terrace</td>\n",
       "      <td>https://www.yelp.com/biz/city-of-mountlake-ter...</td>\n",
       "      <td>47.787910</td>\n",
       "      <td>-122.312750</td>\n",
       "      <td>Mountlake Terrace</td>\n",
       "      <td>US</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>WA</td>\n",
       "      <td>5906 232nd St SW</td>\n",
       "      <td>98043</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>4.5</td>\n",
       "      <td>None</td>\n",
       "      <td></td>\n",
       "      <td>City of Bellevue</td>\n",
       "      <td>https://www.yelp.com/biz/city-of-bellevue-bell...</td>\n",
       "      <td>47.615850</td>\n",
       "      <td>-122.196880</td>\n",
       "      <td>Bellevue</td>\n",
       "      <td>US</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>WA</td>\n",
       "      <td></td>\n",
       "      <td>98004</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>4.0</td>\n",
       "      <td>$$</td>\n",
       "      <td>+12066212228</td>\n",
       "      <td>Harbor City Restaurant</td>\n",
       "      <td>https://www.yelp.com/biz/harbor-city-restauran...</td>\n",
       "      <td>47.598210</td>\n",
       "      <td>-122.323390</td>\n",
       "      <td>Seattle</td>\n",
       "      <td>US</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>WA</td>\n",
       "      <td>707 S King St</td>\n",
       "      <td>98104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>3.5</td>\n",
       "      <td>None</td>\n",
       "      <td>+12064480509</td>\n",
       "      <td>Churchome</td>\n",
       "      <td>https://www.yelp.com/biz/churchome-seattle?adj...</td>\n",
       "      <td>47.616320</td>\n",
       "      <td>-122.351000</td>\n",
       "      <td>Seattle</td>\n",
       "      <td>US</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>WA</td>\n",
       "      <td>2700 1st Ave</td>\n",
       "      <td>98121</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>4.5</td>\n",
       "      <td>$$</td>\n",
       "      <td>+12064864743</td>\n",
       "      <td>Windy City Pie</td>\n",
       "      <td>https://www.yelp.com/biz/windy-city-pie-seattl...</td>\n",
       "      <td>47.672348</td>\n",
       "      <td>-122.354060</td>\n",
       "      <td>Seattle</td>\n",
       "      <td>US</td>\n",
       "      <td>None</td>\n",
       "      <td></td>\n",
       "      <td>WA</td>\n",
       "      <td>5918 Phinney Ave N</td>\n",
       "      <td>98103</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>4.0</td>\n",
       "      <td>None</td>\n",
       "      <td>+12069052100</td>\n",
       "      <td>Space Needle</td>\n",
       "      <td>https://www.yelp.com/biz/space-needle-seattle?...</td>\n",
       "      <td>47.620490</td>\n",
       "      <td>-122.349230</td>\n",
       "      <td>Seattle</td>\n",
       "      <td>US</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>WA</td>\n",
       "      <td>400 Broad St</td>\n",
       "      <td>98109</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>2.5</td>\n",
       "      <td>None</td>\n",
       "      <td></td>\n",
       "      <td>City of Lynnwood</td>\n",
       "      <td>https://www.yelp.com/biz/city-of-lynnwood-lynn...</td>\n",
       "      <td>47.826014</td>\n",
       "      <td>-122.293353</td>\n",
       "      <td>Lynnwood</td>\n",
       "      <td>US</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>WA</td>\n",
       "      <td>None</td>\n",
       "      <td>98036</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>3.5</td>\n",
       "      <td>None</td>\n",
       "      <td>+14258033233</td>\n",
       "      <td>Churchome</td>\n",
       "      <td>https://www.yelp.com/biz/churchome-kirkland?ad...</td>\n",
       "      <td>47.683784</td>\n",
       "      <td>-122.166012</td>\n",
       "      <td>Kirkland</td>\n",
       "      <td>US</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>WA</td>\n",
       "      <td>9051 132nd Ave NE</td>\n",
       "      <td>98033</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>3.5</td>\n",
       "      <td>None</td>\n",
       "      <td>+14257325300</td>\n",
       "      <td>City Center Bellevue</td>\n",
       "      <td>https://www.yelp.com/biz/city-center-bellevue-...</td>\n",
       "      <td>47.615010</td>\n",
       "      <td>-122.195890</td>\n",
       "      <td>Bellevue</td>\n",
       "      <td>US</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>WA</td>\n",
       "      <td>500 108th Ave NE</td>\n",
       "      <td>98004</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>5.0</td>\n",
       "      <td>None</td>\n",
       "      <td>+13603224511</td>\n",
       "      <td>Law Offices of D Merrit and Associates</td>\n",
       "      <td>https://www.yelp.com/biz/law-offices-of-d-merr...</td>\n",
       "      <td>47.578411</td>\n",
       "      <td>-122.149242</td>\n",
       "      <td>Bellevue</td>\n",
       "      <td>US</td>\n",
       "      <td>Ste 100</td>\n",
       "      <td></td>\n",
       "      <td>WA</td>\n",
       "      <td>14205 SE 36th St</td>\n",
       "      <td>98006</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>5.0</td>\n",
       "      <td>$$</td>\n",
       "      <td>+12065695068</td>\n",
       "      <td>Jet City Device Repair</td>\n",
       "      <td>https://www.yelp.com/biz/jet-city-device-repai...</td>\n",
       "      <td>47.651694</td>\n",
       "      <td>-122.336104</td>\n",
       "      <td>Seattle</td>\n",
       "      <td>US</td>\n",
       "      <td>None</td>\n",
       "      <td></td>\n",
       "      <td>WA</td>\n",
       "      <td>3642 Wallingford Ave N</td>\n",
       "      <td>98103</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>4.5</td>\n",
       "      <td>None</td>\n",
       "      <td></td>\n",
       "      <td>City of Bothell</td>\n",
       "      <td>https://www.yelp.com/biz/city-of-bothell-bothe...</td>\n",
       "      <td>47.762009</td>\n",
       "      <td>-122.203178</td>\n",
       "      <td>Bothell</td>\n",
       "      <td>US</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>WA</td>\n",
       "      <td></td>\n",
       "      <td>98011</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>4.5</td>\n",
       "      <td>None</td>\n",
       "      <td>+12063053910</td>\n",
       "      <td>The Fry Guys</td>\n",
       "      <td>https://www.yelp.com/biz/the-fry-guys-seattle?...</td>\n",
       "      <td>47.587070</td>\n",
       "      <td>-122.333740</td>\n",
       "      <td>Seattle</td>\n",
       "      <td>US</td>\n",
       "      <td>None</td>\n",
       "      <td></td>\n",
       "      <td>WA</td>\n",
       "      <td>1740 1st Ave S</td>\n",
       "      <td>98134</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    rating price         phone                                    name  \\\n",
       "0      3.5  None  +12066842489                         City of Seattle   \n",
       "1      3.5     $  +12063231715                             City Market   \n",
       "2      4.0    $$  +12066829329                               City Fish   \n",
       "3      3.0   $$$  +12064413663                              City Foods   \n",
       "4      5.0  None  +12066824424                       City Chiropractic   \n",
       "5      4.5    $$  +12063240737              City People's Garden Store   \n",
       "6      3.0    $$  +12064943250                                  Target   \n",
       "7      3.0  None  +14257756477               City of Mountlake Terrace   \n",
       "8      4.5  None                                      City of Bellevue   \n",
       "9      4.0    $$  +12066212228                  Harbor City Restaurant   \n",
       "10     3.5  None  +12064480509                               Churchome   \n",
       "11     4.5    $$  +12064864743                          Windy City Pie   \n",
       "12     4.0  None  +12069052100                            Space Needle   \n",
       "13     2.5  None                                      City of Lynnwood   \n",
       "14     3.5  None  +14258033233                               Churchome   \n",
       "15     3.5  None  +14257325300                    City Center Bellevue   \n",
       "16     5.0  None  +13603224511  Law Offices of D Merrit and Associates   \n",
       "17     5.0    $$  +12065695068                  Jet City Device Repair   \n",
       "18     4.5  None                                       City of Bothell   \n",
       "19     4.5  None  +12063053910                            The Fry Guys   \n",
       "\n",
       "                                                  url   latitude  longtitude  \\\n",
       "0   https://www.yelp.com/biz/city-of-seattle-seatt...  47.602820 -122.329260   \n",
       "1   https://www.yelp.com/biz/city-market-seattle?a...  47.617043 -122.326439   \n",
       "2   https://www.yelp.com/biz/city-fish-seattle-2?a...  47.608754 -122.340636   \n",
       "3   https://www.yelp.com/biz/city-foods-seattle?ad...  47.617890 -122.345820   \n",
       "4   https://www.yelp.com/biz/city-chiropractic-sea...  47.612790 -122.336560   \n",
       "5   https://www.yelp.com/biz/city-peoples-garden-s...  47.624580 -122.294240   \n",
       "6   https://www.yelp.com/biz/target-seattle-7?adju...  47.608941 -122.339058   \n",
       "7   https://www.yelp.com/biz/city-of-mountlake-ter...  47.787910 -122.312750   \n",
       "8   https://www.yelp.com/biz/city-of-bellevue-bell...  47.615850 -122.196880   \n",
       "9   https://www.yelp.com/biz/harbor-city-restauran...  47.598210 -122.323390   \n",
       "10  https://www.yelp.com/biz/churchome-seattle?adj...  47.616320 -122.351000   \n",
       "11  https://www.yelp.com/biz/windy-city-pie-seattl...  47.672348 -122.354060   \n",
       "12  https://www.yelp.com/biz/space-needle-seattle?...  47.620490 -122.349230   \n",
       "13  https://www.yelp.com/biz/city-of-lynnwood-lynn...  47.826014 -122.293353   \n",
       "14  https://www.yelp.com/biz/churchome-kirkland?ad...  47.683784 -122.166012   \n",
       "15  https://www.yelp.com/biz/city-center-bellevue-...  47.615010 -122.195890   \n",
       "16  https://www.yelp.com/biz/law-offices-of-d-merr...  47.578411 -122.149242   \n",
       "17  https://www.yelp.com/biz/jet-city-device-repai...  47.651694 -122.336104   \n",
       "18  https://www.yelp.com/biz/city-of-bothell-bothe...  47.762009 -122.203178   \n",
       "19  https://www.yelp.com/biz/the-fry-guys-seattle?...  47.587070 -122.333740   \n",
       "\n",
       "                 city country  address2 address3 state  \\\n",
       "0             Seattle      US                       WA   \n",
       "1             Seattle      US                       WA   \n",
       "2             Seattle      US                       WA   \n",
       "3             Seattle      US                       WA   \n",
       "4             Seattle      US  Ste 1645             WA   \n",
       "5             Seattle      US                       WA   \n",
       "6             Seattle      US                       WA   \n",
       "7   Mountlake Terrace      US      None     None    WA   \n",
       "8            Bellevue      US                       WA   \n",
       "9             Seattle      US                       WA   \n",
       "10            Seattle      US                       WA   \n",
       "11            Seattle      US      None             WA   \n",
       "12            Seattle      US                       WA   \n",
       "13           Lynnwood      US      None     None    WA   \n",
       "14           Kirkland      US                       WA   \n",
       "15           Bellevue      US                       WA   \n",
       "16           Bellevue      US   Ste 100             WA   \n",
       "17            Seattle      US      None             WA   \n",
       "18            Bothell      US                       WA   \n",
       "19            Seattle      US      None             WA   \n",
       "\n",
       "                  address1 zip_code  \n",
       "0                             98104  \n",
       "1        1722 Bellevue Ave    98122  \n",
       "2             1535 Pike Pl    98101  \n",
       "3             2522 5th Ave    98121  \n",
       "4            509 Olive Way    98101  \n",
       "5        2939 E Madison St    98112  \n",
       "6             1401 2nd Ave    98101  \n",
       "7         5906 232nd St SW    98043  \n",
       "8                             98004  \n",
       "9            707 S King St    98104  \n",
       "10            2700 1st Ave    98121  \n",
       "11      5918 Phinney Ave N    98103  \n",
       "12            400 Broad St    98109  \n",
       "13                    None    98036  \n",
       "14       9051 132nd Ave NE    98033  \n",
       "15        500 108th Ave NE    98004  \n",
       "16        14205 SE 36th St    98006  \n",
       "17  3642 Wallingford Ave N    98103  \n",
       "18                            98011  \n",
       "19          1740 1st Ave S    98134  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = await dc.query(\"businesses\", _q=\"city\", location=\"seattle\")\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "From query results, you can see how easy it is to download the restaurant data from Yelp into a pandas Dataframe. \n",
    "\n",
    "Now that you have an understanding of how connector operates, you can easily accomplish the task with two lines of code.\n",
    "\n",
    ">1. dc = Connector(...)\n",
    ">2. dc.query(...)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# That's all for now. \n",
    "If you are interested in writing your own configuration file or modify an existing one, refer to the [Configuration Files](https://github.com/sfu-db/DataConnectorConfigs>)."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
